# 服务端
import socket
from threading import Thread

server = socket.socket()
server.bind(('127.0.0.1', 8080))
server.listen(5)


def task(conn):
    while True:
        try:
            data = conn.recv(1024)
            if len(data) == 0:
                break
            print(data.decode('utf-8'))
            conn.send(data.upper())
        except ConnectionError as e:
            print(e)
            break
    conn.close()


if __name__ == '__main__':
    while True:
        conn, addr = server.accept()
        t = Thread(target=task,args=(conn,))
        t.start()
